perf(session): trace switch lifecycle - #667
Open
beruro wants to merge 2 commits into
Open
Conversation
beruro
force-pushed
the
junyu/session-switch-performance-trace
branch
from
August 4, 2026 05:26
1f7d133 to
373410f
Compare
beruro
marked this pull request as ready for review
August 4, 2026 05:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Session switching crosses WorkStation tab focus, session selection, Rust event-store hydration, Jotai state commit, and React paint, but there is no shared timing trace across those owners. This makes it difficult to identify whether a slow switch is caused by data loading, state commit, or rendering, and encourages performance conclusions based only on code inspection.
Solution
Add a bounded User Timing trace for the session-switch lifecycle. Entry points start or join a session-scoped trace; the pipeline records cache, persistence, hydration, state-commit, and data-ready stages;
ChatViewfinishes the trace after two animation frames once the matching session is loaded. One active trace and the latest 20 completed traces are retained, stale browser timing entries are cleared, and abort/unmount paths cancel or finish matching work.This PR adds measurement infrastructure only. It does not claim that switching is faster.
Potential risks
ChatViewnow observes the pipeline session ID and load status, so those atom changes can cause an additional render of the mounted chat view. User Timing work also adds small CPU and memory overhead during a switch. Retention is bounded and no idle loop, persistent storage, network I/O, or cross-window state is introduced, but a packaged desktop/WebView profile has not yet measured the runtime overhead or validated the usefulness of the resulting timeline. The trace can be reviewed and merged independently because this PR makes no speedup claim; the packaged profile remains follow-up measurement evidence. Rollback is a source-only revert; no data or compatibility migration is involved.Performance guard
The lifecycle and resource audit is recorded in
docs/org2-performance-guard-2026-08-04/SessionSwitchPerformanceTrace.md. Verdict: bounded and lifecycle-safe by inspection and unit coverage; real WebView measurement remains pending.Verification
npx vitest run src/engines/SessionCore/performance/sessionSwitchPerformance.test.ts src/engines/SessionCore/sync/__tests__/sessionSwitchOrchestrator.test.ts src/engines/SessionCore/core/atoms/__tests__/actions.test.ts src/store/session/__tests__/viewAtom.test.ts src/store/workstation/tabRegistry/atoms.test.ts— 5 files, 44 tests passed.npx eslintover all changed TypeScript/TSX files — passed.npm run typecheck— passed.git diff --cached --checkbefore commit — passed.origin/develop; every file maps to the session-switch trace or its performance audit.Not run: packaged desktop/WebView timing capture and multi-window manual profiling. No user-visible layout changes are included, so screenshots would not provide useful evidence.